package jdbc;

import jdbc.common.InputUtil;
import org.w3c.dom.ls.LSOutput;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class LoginUserDemo {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("用户登录");
        System.out.println("请输入用户名：");
        String username=scanner.next();
        System.out.println("请输入密码：");
        String password=scanner.next();
        try(Connection connection=DBUtil.getconnection()){
            Statement statement=connection.createStatement();

            String sql="SELECT username,password,nickname,age  " +
                    "FROM userinfo  " +
                    "WHERE username='"+username+"'AND password='"+password+"'";
            ResultSet rs=statement.executeQuery(sql);
            if(rs.next()){
                String nickname=rs.getString("nickname");
                System.out.println("登录成功！欢迎您："+nickname);

            }else {
                System.out.println("用户名或密码错误！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

